home *** CD-ROM | disk | FTP | other *** search
/ Champak 114 / Vol 114.iso / games / harry_po.swf / scripts / frame_14 / DoAction_3.as < prev    next >
Encoding:
Text File  |  2010-08-12  |  1.3 KB  |  41 lines

  1. isometricAS = function(maxx, maxz)
  2. {
  3.    this.maxx = maxx;
  4.    this.maxz = maxz;
  5.    this.theta = 30;
  6.    this.alpha = 45;
  7.    this.theta *= 0.017453292519943295;
  8.    this.alpha *= 0.017453292519943295;
  9.    this.sinTheta = Math.sin(this.theta);
  10.    this.cosTheta = Math.cos(this.theta);
  11.    this.sinAlpha = Math.sin(this.alpha);
  12.    this.cosAlpha = Math.cos(this.alpha);
  13. };
  14. isometricAS.prototype.mapToScreen = function(xpp, ypp, zpp)
  15. {
  16.    var yp = ypp;
  17.    var xp = xpp * this.cosAlpha + zpp * this.sinAlpha;
  18.    var zp = zpp * this.cosAlpha - xpp * this.sinAlpha;
  19.    var x = xp;
  20.    var y = yp * this.cosTheta - zp * this.sinTheta;
  21.    return [x,y];
  22. };
  23. isometricAS.prototype.mapToIsoWorld = function(screenX, screenY)
  24. {
  25.    var z = (screenX / this.cosAlpha - screenY / (this.sinAlpha * this.sinTheta)) * (1 / (this.cosAlpha / this.sinAlpha + this.sinAlpha / this.cosAlpha));
  26.    var x = 1 / this.cosAlpha * (screenX - z * this.sinAlpha);
  27.    return [x,z];
  28. };
  29. isometricAS.prototype.calculateDepth = function(x, y, z)
  30. {
  31.    var leeway = 5;
  32.    var x = Math.abs(x) * leeway;
  33.    var y = Math.abs(y);
  34.    var z = Math.abs(z) * leeway;
  35.    var a = this.maxx;
  36.    var b = this.maxz;
  37.    var floor = a * (b - 1) + x;
  38.    var depth = a * (z - 1) + x + floor * y;
  39.    return depth;
  40. };
  41.